package com.huajiao.management_system.service.impl;

import com.huajiao.management_system.bean.*;
import com.huajiao.management_system.dao.*;
import com.huajiao.management_system.service.resService;
import com.huajiao.management_system.util.PageQueryUtil;
import com.huajiao.management_system.util.PageResult;
import com.huajiao.management_system.util.mergeListUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@Service
public class resServiceImpl implements resService {
    @Resource
    private competitionResMapper competitionResmapper;
    @Resource
    private honorResMapper honorResmapper;
    @Resource
    private paperResMapper paperResmapper;
    @Resource
    private patentResMapper patentResmapper;
    @Resource
    private softwarecopyrightResMapper softwarecopyrightResmapper;


    private mergeListUtil mergelistUtil;
    //查询结果总数
    int total;

    @Override
    public PageResult selectPage(String Time, String keyword, Integer page) {
        List<competitionRes> competitionResList = null;
        List<honorRes> honorResList = null;
        List<paperRes> paperResList = null;
        List<patentRes> patentResList = null;
        List<softwarecopyrightRes> softwarecopyrightResList = null;
        Map param = new LinkedHashMap();
        param.put("Time", Time);
        param.put("keyword", keyword);
        if (page == 0 ) {
            PageResult pageResult = new PageResult("错误页数！");
            return pageResult;
        }
        if (page == 1) {
            competitionResList = competitionResmapper.selectByKeyword(param);

            honorResList = honorResmapper.selectByKeyword(param);

            paperResList = paperResmapper.selectByKeyword(param);

            patentResList = patentResmapper.selectByKeyword(param);

            softwarecopyrightResList = softwarecopyrightResmapper.selectByKeyword(param);

            mergelistUtil = new mergeListUtil(competitionResList, honorResList, paperResList, patentResList, softwarecopyrightResList);
            int total1 = competitionResmapper.getTotalcompetitionRes(param);
            int total2 = honorResmapper.getTotalhonorRes(param);
            int total3 = paperResmapper.getTotalpaperRes(param);
            int total4 = patentResmapper.getTotalpatentRes(param);
            int total5 = softwarecopyrightResmapper.getTotalsoftwarecopyrightRes(param);
            total = total1 + total2 + total3 + total4 + total5;
        }

        PageQueryUtil pageUtil = new PageQueryUtil(mergelistUtil.getMergeList(), page);
        PageResult pageResult = new PageResult(pageUtil.getPagelist(), total, pageUtil.getPageSize(), pageUtil.getPage());
        return pageResult;
    }

}
